Skip to content

Conversation

@shihab-dls
Copy link
Contributor

@shihab-dls shihab-dls commented Jan 22, 2026

closes #306 and closes #133

Adds an always flag to add_on_update_callback, and checks this flag when deciding what callback to call in update.

@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.69%. Comparing base (c43f71b) to head (470d6b2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #311   +/-   ##
=======================================
  Coverage   90.69%   90.69%           
=======================================
  Files          70       70           
  Lines        2535     2537    +2     
=======================================
+ Hits         2299     2301    +2     
  Misses        236      236           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shihab-dls shihab-dls marked this pull request as ready for review January 23, 2026 11:16
@shihab-dls shihab-dls requested a review from GDYendell January 23, 2026 11:16
@shihab-dls shihab-dls changed the title feat: add always flag to add_on_update_callback Add always flag to add_on_update_callback Jan 23, 2026
@shihab-dls
Copy link
Contributor Author

Tested with fastcs-PandaBlocks; BitGroupOnUpdate can be reduced to:

@dataclass
class BitGroupOnUpdate:
    """Bits are tied together in bit groups so that when one is set for capture,
    they all are.

    This callback sets all capture attributes in the group when one of them is set.
    """

    capture_attribute: AttrRW[enum.Enum]
    bit_attributes: list[AttrRW[bool]]

    async def __call__(self, value: Any):
        if isinstance(value, enum.Enum):
            bool_value = bool(self.capture_attribute.datatype.index_of(value))  # type: ignore
            enum_value = value
        else:
            bool_value = value
            assert isinstance(self.capture_attribute.datatype, Enum)
            enum_value = self.capture_attribute.datatype.members[int(value)]

        await asyncio.gather(
            *(bit_attr.update(bool_value) for bit_attr in self.bit_attributes),
            self.capture_attribute.update(enum_value),
        )

removing the need for:

async def _set_attr_if_not_already_value(attribute: AttrRW[DType_T], value: DType_T):
    if attribute.get() != value:
        await attribute.update(value)

So, this PR will be updated to close #133, as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add only_on_change flag to add_on_update_callback Allow setting an AttrR/AttrRW without running the callbacks added downstream

3 participants